export default class Coordinate {
  onAdd(map) {
    this._map = map
    this._container = document.createElement('div')
    this.lngdiv = document.createElement('div')
    this.lngdiv.className = 'coordinate-lng'
    this.latdiv = document.createElement('div')
    this.latdiv.className = 'coordinate-lat'
    this._container.className = 'map-coordinate'
    this._container.appendChild(this.lngdiv)
    this._container.appendChild(this.latdiv)
    map.on('mousemove', this._mouseMoveEvent.bind(this))
    return this._container
  }

  onRemove() {
    this._container.parentNode.removeChild(this._container)
    this._map = undefined
    this._map.off('mousemove', this._mouseMoveEvent.bind(this))
  }

  _mouseMoveEvent(e) {
    this.lngdiv.innerText = '经度：' + e.lngLat.lng.toFixed(5)
    this.latdiv.innerText = '纬度：' + e.lngLat.lat.toFixed(5)
  }
}

